/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.co.drpj.midi.router;

import java.io.File;
import java.io.IOException;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiEvent;
import javax.sound.midi.MidiMessage;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Sequence;
import javax.sound.midi.ShortMessage;
import javax.sound.midi.Track;

/**
 *
 * @author pjl
 */
public class MidiReader {

    public static void main(String args[]) throws InvalidMidiDataException, IOException {
        File file = new File("/home/pjl/MIDI/A07.mid");

        Sequence seq = MidiSystem.getSequence(file);

        for (Track track : seq.getTracks()) {
            for (int i = 0; i < track.size(); i++) {
                MidiEvent event = track.get(i);
                MidiMessage mess = event.getMessage();
                if (event.getMessage() instanceof ShortMessage) {
                    ShortMessage shm = (ShortMessage) event.getMessage();
                    if (shm.getCommand() == ShortMessage.NOTE_ON || shm.getCommand() == ShortMessage.NOTE_OFF) {
                     
                        int cc = shm.getData1();
                        int hh = shm.getData2();

                    }

                }

            }

        }
    }
}